<?php 
class User
{
	public function construct()
	{
		
	}

        public function index()
        { 
            CommonFunc::loadFile(SMARTYLIBS . "Smarty.class.php");
		CommonFunc::loadFile("model/User.php");
		$smarty = new Smarty();
		$modUser = new ModelUser();
                $user_arr=$modUser->getUserlist();
               // print_r($user_arr);
		$smarty->debugging = false;
		$smarty->caching = false;
		$smarty->cache_lifetime = 120;
                $smarty->debugging = true;
		$smarty->assign("title", "User Management");
		$smarty->assign("user_arr", $user_arr);
		$smarty->display('user/index.tpl');
        }

        public function addUser()
	{
		CommonFunc::loadFile(SMARTYLIBS . "Smarty.class.php");
		CommonFunc::loadFile(ADAPTOR . "/EditorFCK.php");
		CommonFunc::loadFile('model/Category.php');
		CommonFunc::loadFile('model/Product.php');
		$smarty = new Smarty();
		$smarty->assign("title", "Add User");
		$smarty->display("user/adduser.tpl");
	}

         

             public function editUser($userid)
	{
		CommonFunc::loadFile(SMARTYLIBS . "Smarty.class.php");
		CommonFunc::loadFile(ADAPTOR . "/EditorFCK.php");
		CommonFunc::loadFile('model/User.php');
                $modUser=new ModelUser();
                $request = CommonFunc::getRequest();
		$userid = $request['param1'];
                //echo $userid;
		$user_arr = $modUser->getUserbyID($userid);
                //print_r($user_arr);
                $usertype=array();
                $usertype=array(0=>array('val'=>1,'dsc'=>"Normal User"),1=>array('val'=>2,'dsc'=>"Business User"));
                $options=array();
                $options=array(0=>array('val'=>0,'dsc'=>"hide"),1=>array('val'=>1,'dsc'=>"show"));
                /*if($user_arr[0][0]["usertype"]==2){
                    $normaluserstyle=" display:none; ";
                    $businessuserstyle="";
                }
                else{
                     $normaluserstyle="";
                    $businessuserstyle=" display:none; ";
                }
                echo "<br>";
                echo "normaluserstyle".$normaluserstyle;
                echo "<br>";
                echo "businessuserstyle". $businessuserstyle;*/
               // print_r($options);
                $creditorcheck=($user_arr[0]["iscreditor"]==1)?"checked":"";
		$smarty = new Smarty();
                $smarty->assign("creditorcheck", $creditorcheck);
                $smarty->assign("user_arr", $user_arr);
                $smarty->assign("options", $options);
                $smarty->assign("usertype", $usertype);
                $smarty->assign("normaluserstyle", $normaluserstyle);
                $smarty->assign("businessuserstyle", $businessuserstyle);
		$smarty->assign("title", "Edit  User");
                $smarty->assign("checkbusinessuser",$checkbusinessuser);
                $smarty->assign("checknormaluser", $checknormaluser);
		$smarty->display("user/edituser.tpl");
	}

	
	public function authUser($username, $password)
	{
		CommonFunc::loadFile('model/User.php');
		$modUser = new ModelUser();
		if($username == "")
		{
			echo "<span class='error'>Username cannot be empty</span>|error";
		} else if($password == "") {
			echo "<span class='error'>Password cannot be empty</span>|error";
		} else {		
			$user_arr = $modUser->getUserInfo($username, $password);
			if(count($user_arr) > 1)
			{
				$adminId = $user_arr['admin_id'];
				$adminFname = $user_arr['admin_firstname'];
				$adminLname = $user_arr['admin_lastname'];
				session_register('admin_id');
				$_SESSION['admin_id'] = $adminId;
				$_SESSION['adminFname'] = $adminFname;
				$_SESSION['adminLname'] = $adminLname;
				echo "<span class='success'>User Validation Completed</span>|success";
			} else {
				echo "<span class='error'>Invalid Username or Password</span>|error";
			}
		}	
	}	
}
?>